<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="js/jquery-3.5.1.js"></script>
    <title>Document</title>

</head>

<body>
    水果：<input id="fruitName" type="text" name="fruitName"><br>
    价格：<input id="fruitPrice" type="text" name="fruitPrice"><br>
    <button id="postBtn">添加水果信息</button>

    <script type="text/javascript">
        $("#postBtn").click(function () {
            $.ajax({
                type: 'post',
                url: 'http://localhost:3000/fruits',
                data: {
                    name: $("#fruitName").val(),
                    price: $("#fruitPrice").val()
                },
                success: function (data) {
                    alert("添加成功")
                },
                error: (function () {
                    alert("post error")
                })
            })
        })
    </script>
</body>

</html>